package com.atstudy.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/1/30 10:44
 * @copyright: 博为峰
 */
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //----------------------------------请求------------------------------------------------------------
        String name = req.getParameter("name");
        System.out.println("name = " + name);

        String userAgent = req.getHeader("user-agent");
        System.out.println("userAgent = " + userAgent);

        //----------------------------------响应------------------------------------------------------------

        resp.setHeader("bwf", "com.atstudy");
//        resp.setHeader("content-type", "text/html;charset=utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.write("<h1>学掌门</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接收数据之前，设置编码表
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        System.out.println("name = " + name);
    }

    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPut(req, resp);
    }

    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doDelete(req, resp);
    }
}
